﻿using System.Collections.Generic;

namespace RaspberryDebugger
{
    /// <summary>
    /// Holds the Raspberry related settings for projects in a solution.  This is
    /// persisted to <b>$/.vs/raspberry-projects.json</b> in the solution directory.
    /// </summary>
    /// <remarks>
    /// This is simply a dictionary mapping a project's unique name to the settings 
    /// for the project.
    /// </remarks>
    internal class RaspberryProjects : Dictionary<string, ProjectSettings>
    {
        /// <summary>
        /// Accesses the project settings for a project based on its GUID.
        /// </summary>
        /// <param name="projectUnqueName">The project's unique name.</param>
        /// <returns>
        /// The <see cref="ProjectSettings"/> for the project, initializing default 
        /// (disabled) settings if when the project doesn't exist.
        /// </returns>
        public new ProjectSettings this[string projectUnqueName]
        {
            get
            {
                if (base.TryGetValue(projectUnqueName, out var settings))
                {
                    return settings;
                }
                else
                {
                    settings = new ProjectSettings();

                    this[projectUnqueName] = settings;

                    return settings;
                }
            }

            set => base[projectUnqueName] = value;
        }
    }
}
